<%@ include file="/common/taglibs.jsp"%>
<%@ page pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<script type="text/javascript" src="${jquery}/jquery.js"></script>
		<script type="text/javascript" src="${jquery}/jquery.validate.js"></script>
		<script type="text/javascript" src="${jquery}/jquery.form.js"></script>
		<script type="text/javascript" src="${jquery}/messages_cn.js"></script>
		<script type="text/javascript" src="${easyui}/jquery.easyui.min.js"></script>
		<link rel="stylesheet" type="text/css"
			href="${easyui}/themes/icon.css">
		<link rel="stylesheet" type="text/css"
			href="${easyui}/themes/default/easyui.css">
		<link href="${app}/hnjz.css" rel="stylesheet" type="text/css">

		<script type="text/javascript"
			src="${colorbox}/jquery.colorbox-min.js"></script>
		<link rel="stylesheet" type="text/css" href="${colorbox}/colorbox.css">
	</HEAD>

	<body>
		<div class="divContainer">
			<form id="myform" style="padding: 5px 20px 20px 20px" name="myform" method="post"
				action="saveFun.json">
				<table class="formtable">
				<input type="hidden" value="${funForm.id}" id="id" name="id">
				<input type="hidden" value="${funForm.data}" id="data" name="data">
				<div id="neirong" style="padding: 5px;">
					<tr>
						<th>
							<span class="mark">*</span>功能名称：
						</th>
						<td>
							<input class="i-text" type="text" id="funcName" name="funcName"
							value="${funForm.funcName}" />
						</td>
					</tr>
					<tr>
						<th>
							父功能
						</th>
						<td>
							<input type="hidden" value="${funForm.parent}" id="parent"
							name="parent">
						<input class="i-text" type="text" readonly="true"
							value="${funForm.parentName}" id="parentName" name="parentName" />
						<a href="funPubQuery.htm" id="selectParent">选择父功能</a>
						</td>
					</tr>
					<tr>
						<th>
							功能连接：
						</th>
						<td>
							<input class="i-text" type="text" value="${funForm.linkaddr}"
							id="linkaddr" name="linkaddr" />
						</td>
					</tr>
					<tr>
						<th>
							<span class="mark">*</span>	排序：
						</th>
						<td>
							<input class="i-text" type="text" value="${funForm.orderby}"
							id="orderby" name="orderby" />
						</td>
					</tr>
					<tr>
						<th>
							<span class="mark">*</span>功能说明：
						</th>
						<td>
							<input class="i-text" type="text" value="${funForm.funcDesc}"
							id="funcDesc" name="funcDesc" />
						</td>
					</tr>
					<div style="padding: 5px 20px 20px 50px;">
						<table id="functionOp" title="添加菜单对应的操作，例如：增加，删除"
							style="width: 630px; height: 280px" iconCls="icon-edit"
							singleSelect="true" idField="name">
							<thead>
								<tr>
									<th field="name" width="90" editor="{type:'text',field:'name'}">
										操作名称
									</th>
									<th field="onclickEvent" width="90" editor="{type:'text'}">
										点击事件
									</th>
									<th field="linkAddr" width="340" editor="{type:'text'}">
										对应链接
									</th>
									<th field="fashion" width="80"
										editor="{type:'combobox',
										         options:{required:true,
										                  editable:false,
										                  data:[
										                        {'id':'0','text':'列表显示'},
										                        {'id':'1','text':'列表不显示'},
										                        {'id':'2','text':'所有都不显示'}
										                        ],
										                  valueField:'id',
										                  textField:'text'}}">  

										列表是否显示
									</th>
									<th field="id" width="1" editor="{type:'text'}">
									</th>
								</tr>
							</thead>
						</table>
					</div>
					<div class="fm-item">
						<span class="btn btn-ok"> <input type="submit" value="提交">
						</span>&nbsp;
						<a href="#" id="J-from-reset">重置</a>
					</div>
				</div>
				</table>
			</form>
		</div>
	</body>
</HTML>
<SCRIPT LANGUAGE="JavaScript">
function setFunctionInfo(id,name) {
    $('#parent').val(id)
    $('#parentName').val(name)
    $('#parentName').focus();
    jQuery().colorbox.close();
}
var lastIndex;
var dataG;
$(document).ready(function(){
     dataG = $('#functionOp').datagrid({
        url:'functionOpt.json?id=${funForm.id}',
		toolbar:[{
			text:'添加',
			iconCls:'icon-add',
			handler:function(){
				$('#functionOp').datagrid('endEdit', lastIndex);
				$('#functionOp').datagrid('appendRow',{
				    id:'',
					name:'',
					onclickEvent:'',
					linkAddr:'',
					fashion:'1'
				});
				lastIndex = $('#functionOp').datagrid('getRows').length-1;
				$('#functionOp').datagrid('selectRow', lastIndex);
				$('#functionOp').datagrid('beginEdit', lastIndex);
		    }},{
			text:'删除',
			iconCls:'icon-remove',
				handler:function(){
                var row = $('#functionOp').datagrid('getSelected');
				if (row){
					var index = $('#functionOp').datagrid('getRowIndex', row);
					$('#functionOp').datagrid('deleteRow', index);
				}
				}},{
			text:'删除全部',
			iconCls:'icon-remove',
			handler:function(){
                var ll = $('#functionOp').datagrid('getRows').length-1;
                for(i=ll;i>=0;i--){
                	$('#functionOp').datagrid('deleteRow', i);
                }
		    },
		}],
	    onClickRow:function(rowIndex){
	  		if (lastIndex != rowIndex){
				$('#functionOp').datagrid('endEdit', lastIndex);
				$('#functionOp').datagrid('beginEdit', rowIndex);
			}
			lastIndex = rowIndex;
		}
	});
    $("#selectParent").colorbox({iframe:true,width:"300", height:"400"});
	$("#J-from-reset").click(function(){
	   $("#myform").reset();
	});
   	//表单校验
    $("#myform").validate(
    {
          errorClass: "error",
          submitHandler:function(form){
              dataG.datagrid('acceptChanges');
	          var data = JSON.stringify(dataG.datagrid('getData'));
	          $('#data').val(data);
		      $(form).ajaxSubmit({
		        type:"post",
		        dataType:"json",
		        url:"saveFun.json",
		        success: function(data){
		          $.messager.alert('保存功能菜单:',data.msg);
		          if(data.state){
			          parent.ref();
			       }
		        }
		      });
		  },
          rules:
          {  
			 "funcName": { required: true },
			 "funcDesc": { required: true },
			 "orderby": { required: true }
          }
     });
});
</SCRIPT>